-
-
Notifications
You must be signed in to change notification settings - Fork 615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[14.0][IMP] mail_tracking: add job to delete old tracking records #1430
[14.0][IMP] mail_tracking: add job to delete old tracking records #1430
Conversation
37b4f95
to
4e36e51
Compare
Do you have some metrics about performance degradation that leads to this action? |
@pedrobaeza this action is here to reduce the DB size (to speed up backup and restore operations mainly), currently we have a DB with the |
OK, thanks for the information. It's good to add this information initially (and include it in the commit message) for avoiding to guess what is the improvement. It would be interesting to check if there's a way to optimize the DB schema of this table to reduce this size as well. Maybe there's a related stored or similar fields that increase the size a lot. |
34e286e
to
36b36cf
Compare
Thank you @pedrobaeza for checking. I don't have anything to add to @sebalix comment but I added the relevant details to the description 👍 |
36b36cf
to
dc9ef3c
Compare
dc9ef3c
to
7e95078
Compare
Test added to the |
@henrybackman when you push again pls report the description in the commit msg. |
7e95078
to
3fa48e9
Compare
records_to_delete = self.search(domain, limit=limit) | ||
_logger.debug("Deleting %s mail.tracking.email records", len(records_to_delete)) | ||
return records_to_delete.unlink() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After testing this on a customer DB, it triggers the following error (linked to related fields):
Traceback (most recent call last):
File "/odoo/src/odoo/addons/base/models/ir_autovacuum.py", line 38, in _run_vacuum_cleaner
func(model)
File "/odoo/external-src/social/mail_tracking/models/mail_tracking_email.py", line 503, in _gc_mail_tracking_email
records_to_delete.unlink()
File "/odoo/external-src/connector/component_event/models/base.py", line 118, in unlink
result = super(Base, self).unlink()
File "/odoo/src/odoo/models.py", line 3501, in unlink
self.flush()
File "/odoo/src/odoo/models.py", line 5472, in flush
self.recompute()
File "/odoo/src/odoo/models.py", line 5931, in recompute
process(field)
File "/odoo/src/odoo/models.py", line 5918, in process
field.recompute(existing)
File "/odoo/src/odoo/fields.py", line 1178, in recompute
self.compute_value(record)
File "/odoo/src/odoo/fields.py", line 1198, in compute_value
records._compute_field_value(self)
File "/odoo/src/odoo/models.py", line 4079, in _compute_field_value
odoo.fields.determine(field.compute, self)
File "/odoo/src/odoo/fields.py", line 85, in determine
return needle(records, *args)
File "/odoo/src/odoo/fields.py", line 574, in _compute_related
record[self.name] = self._process_related(value[self.related_field.name])
File "/odoo/src/odoo/models.py", line 5702, in __getitem__
return self._fields[key].__get__(self, type(self))
File "/odoo/src/odoo/fields.py", line 2495, in __get__
return super().__get__(records, owner)
File "/odoo/src/odoo/fields.py", line 1025, in __get__
_("(Record: %s, User: %s)") % (record, env.uid),
odoo.exceptions.MissingError: Record does not exist or has been deleted.
I tried different things but only a raw DELETE
query is working while being simple:
records_to_delete = self.search(domain, limit=limit) | |
_logger.debug("Deleting %s mail.tracking.email records", len(records_to_delete)) | |
return records_to_delete.unlink() | |
records_to_delete = self.search(domain, limit=limit).exists() | |
if records_to_delete: | |
_logger.info("Deleting %s mail.tracking.email records", len(records_to_delete)) | |
self.flush() | |
query = "DELETE FROM mail_tracking_email WHERE id IN %s" | |
args = (tuple(records_to_delete.ids),) | |
self.env.cr.execute(query, args) | |
self.invalidate_cache() |
722eeeb
to
6ed27f3
Compare
Add autovacuum to mail_tracking_email that removes old records based on new configuration variable mail_tracking_email_max_age_days. Due to possibly a large number of records to be deleted on first run, set a default limit of 5000 per run.
6ed27f3
to
9fd6204
Compare
@pedrobaeza good for you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ocabot merge minor
This PR has the |
What a great day to merge this nice PR. Let's do it! |
Congratulations, your PR was merged at 3bd12c2. Thanks a lot for contributing to OCA. ❤️ |
Records in
mail_tracking_email
table grow over time and increase the database size, which slows down backup and restore operations. (For example, in one customer db themail_tracking_email
table takes almost 2GB)Added
autovacuum
tomail_tracking_email
that removes by default records over 6 months old.The deletion can be enabled with a configuration variable.
Due to possibly a large number of records to be deleted on first run, set a default limit of 5000 per run.